/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.table.legend;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;

import twaver.BTS;
import twaver.BTSAntenna;
import twaver.BaseElement;
import twaver.Card;
import twaver.Chassis;
import twaver.Dummy;
import twaver.ElementAttribute;
import twaver.EllipseGroup;
import twaver.FlexionLink;
import twaver.Group;
import twaver.Link;
import twaver.LinkSubNetwork;
import twaver.OrthogonalLink;
import twaver.ParallelogramGroup;
import twaver.PolySubNetwork;
import twaver.Port;
import twaver.Rack;
import twaver.ShapeLink;
import twaver.ShapeNode;
import twaver.ShapeSubNetwork;
import twaver.Shelf;
import twaver.Slot;
import twaver.SubNetwork;
import twaver.TDataBox;
import twaver.TUIManager;
import twaver.TWaverUtil;
import twaver.TerminalPoint;
import twaver.Node;
import twaver.Text;
import twaver.table.TElementTable;
import demo.DemoPane;

public class LegendDemo extends DemoPane {

	public static class Legend extends Node{
		public Legend(String legendName, String legendIcon){
			this.putClientProperty("legend.name", legendName);
			this.putClientProperty("legend.icon", legendIcon);
		}
	}
	TDataBox box = new TDataBox();
	
	public LegendDemo(){
		TElementTable xmlTable = new TElementTable(box);
		xmlTable.setEditable(false);
		xmlTable.setElementClass(Legend.class);
		xmlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		xmlTable.setRowHeight(24);
		xmlTable.registerElementClassXML(Legend.class, "/demo/table/legend/Legend.xml");
		
		TElementTable apiTable = new TElementTable(box);		
		apiTable.setEditable(false);
		apiTable.setElementClass(Legend.class);
		apiTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		apiTable.setRowHeight(24);
		List attributes = new ArrayList();
		attributes.add(createElementAttribute("legend.name", "Legend Name"));
		attributes.add(createElementAttribute("legend.icon", "Legend Icon"));
		apiTable.registerElementClassAttributes(Legend.class, attributes);
		
		JSplitPane split = new JSplitPane(
				JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(xmlTable), new JScrollPane(apiTable));
		split.setDividerLocation(250);
		this.add(split);
		
        addElement(BaseElement.class);
        addElement(Node.class);
        addElement(Card.class);
        addElement(Slot.class);
        addElement(Chassis.class);
        addElement(Dummy.class);
        addElement(Group.class);
        addElement(EllipseGroup.class);
        addElement(ParallelogramGroup.class);
        addElement(Link.class);
        addElement(LinkSubNetwork.class);
        addElement(ShapeLink.class);
        addElement(FlexionLink.class);
        addElement(OrthogonalLink.class);
        addElement(Port.class);
        addElement(Rack.class);
        addElement(Shelf.class);
        addElement(SubNetwork.class);
        addElement(ShapeNode.class);
        addElement(ShapeSubNetwork.class);
        addElement(PolySubNetwork.class);
        addElement(TerminalPoint.class);
        addElement(BTS.class);
        addElement(BTSAntenna.class);
        addElement(Text.class);
		
		xmlTable.getTableModel().setPageRowSize(10);
		xmlTable.getTableModel().setCurrentPageIndex(2);
	}
	
	private void addElement(Class clazz){
		String name = TWaverUtil.getClassNameWithoutPackage(clazz);
		String icon = TUIManager.getIconUrl(clazz);
		box.addElement(new Legend(name, icon));
	}

	private ElementAttribute createElementAttribute(String key, String dispalyName){
    	ElementAttribute attribute = new ElementAttribute();
    	attribute.setClientPropertyKey(key);
    	attribute.setDisplayName(dispalyName);
    	attribute.setEditable(false);
    	return attribute;
	}
	

}